﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Training
{
    class Program
    {
        public static string HexStr(byte[] p)
        {

            char[] c = new char[p.Length * 2 + 2];

            byte b;

            c[0] = '0'; c[1] = 'x';

            for (int y = 0, x = 2; y < p.Length; ++y, ++x)
            {

                b = ((byte)(p[y] >> 4));

                c[x] = (char)(b > 9 ? b + 0x37 : b + 0x30);

                b = ((byte)(p[y] & 0xF));

                c[++x] = (char)(b > 9 ? b + 0x37 : b + 0x30);

            }

            return new string(c);

        }

        static void Main()
        {

            FileStream fs = new FileStream("example.bin",
  FileMode.Open, FileAccess.ReadWrite, FileShare.None);
            using (fs)
            {
                byte[] buf = new byte[16];
                while (true)
                {
                    int bytesRead = fs.Read(buf, 0, buf.Length);
                    if (bytesRead == 0)
                        break;
                    for (int i = 0; i < bytesRead; i++)
                    {
                        Console.WriteLine(BitConverter.ToString(buf));
                    }
                    //fs.Seek(-bytesRead, SeekOrigin.Current);
                    //fs.Write(buf, 0, bytesRead);
                }
            }

        }
    }
}
